from heapq import heapify, heapreplace
from typing import List


class Solution:
    def maxKelements(self, nums: List[int], k: int) -> int:
        for i in range(len(nums)):
            nums[i] = -nums[i]  # 最大堆
        heapify(nums)  # 列表转换为堆
        ans = 0
        for _ in range(k):
            ans -= heapreplace(nums, nums[0] // 3)
        return ans
